@extends('admin.layout.layout', ['row' => @$page])
@section('style')
    <style>
        .table .tth{
            background-color: rgba(0, 0, 0, 0.05);
            width: 150px;
            font-weight: bold;
        }
        .table .ttd{
            width: 350px;
        }
        .table .ttt{
            padding: 0;
        }
        .ttt .table{
            margin: 0;
        }
        .ttt .table img + p{
            text-align: center;
            margin: 10px 0 0;
        }
        .tst{
            color: #1e89e0;
            font-weight: 700;
            text-align: center;
            font-size: 1.25rem;
        }
        .warranty-image-wrapper .warranty-image-list{
            display: flex;
            flex-wrap: wrap;
        }
        .warranty-image-wrapper .warranty-image-list .item{
            width: 100px;
            flex: 0 0 100px;
            height: 100px;
            padding: 0;
            overflow: hidden;
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            display: block;
        }
        .warranty-image-wrapper .warranty-image-list .item{
            margin: 10px;
        }
        .warranty-image-wrapper .warranty-image-list .item img{
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
    </style>
@endsection
@section('contain')


    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
                {{--<div class="item">
                    <a href="/{{ request()->path() }}/create" class="btn btn-sm btn-primary">{{ ts('addnew') }}</a>
                </div>--}}
            </div>
        </div>

        <div>
            <table class="table s3">
                <tbody>
                {{--<tr>
                    --}}{{--<td class="tth">{{ ts('SQID') }}</td>
                    <td class="ttd" colspan="3">{{ $data->id }}</td>--}}{{--
                    <td class="tth">{{ ts('jxsjb') }}</td>
                    <td class="ttd">{{ ts('mdtype'.$data->mdtype)  }}</td>
                    <td colspan="4"></td>
                </tr>--}}
                <tr>
                    <td colspan="6" class="tst">{{ ts('baseinformation') }}</td>
                </tr>
                <tr>
                    {{--JXSMC--}}
                    <td class="tth">{{ ts('JXSZH') }}</td>
                    <td class="ttd">{{ $data->unique_id}}</td>
                    <td class="tth">{{ ts('dmmc') }}</td>
                    <td class="ttd">{{ $data->abbr}}</td>
                    <td class="tth">{{ ts('companyname') }}</td>
                    <td class="ttd">{{ $data->company_name  }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('jxsjb') }}</td>
                    <td class="ttd">{{ ts('mdtype'.$data->mdtype)  }}</td>
                    <td class="tth">{{ ts('jsdj') }}</td>
                    <td class="ttd">{{ ts('jsdj'.$data->jsdj)  }}</td>
                    <td class="tth">{{ ts('zsdj') }}</td>
                    <td class="ttd">{{ ts('zsdj'.$data->zsdj)  }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('status') }}</td>
                    <td class="ttd">{{ !empty($data->deleted_at) ? ts('jy') : ( $data->status == 1 ? ts('active') : ts('DEACTIVE') ) }}</td>
                    <td class="tth">{{ ts('任务值') }}</td>
                    <td class="ttd">
                        @if (!empty($dealer) && !empty($dealer->task_value))
                            {{ $dealer->task_value }}
                        @else
                            @if (!empty($data->mdtype) && in_array($data->mdtype, [1, 3, 4]))
                                15
                            @endif
                            @if (!empty($data->mdtype) && $data->mdtype == 2)
                                4
                            @endif
                        @endif
                    </td>
                    <td class="tth">{{ ts('审核状态') }}</td>
                    <td class="ttd">
                        {{ $data->check_status == 1 ? '通过' : ($data->check_status ? '拒绝' : '待审核') }}
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('top100') }}</td>
                    <td class="ttd">{{ $data->top100 == 0 ? '否' :($data->top100==1 ? '金' : '银') }}</td>
                    <td class="tth">&nbsp;</td>
                    <td class="ttd">&nbsp;</td>
                    <td class="tth">&nbsp;</td>
                    <td class="ttd">&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('contactinformation') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('LXR') }}</td>
                    <td>{{ $data->first_name }}</td>

                    <td class="tth">{{ ts('phonenumber') }}</td>
                    <td class="ttd">{{ $data->extension }} {{ $data->phone_number }}</td>
                    <td class="tth">{{ ts('email') }}</td>
                    <td class="ttd">{{ $data->email_address }}</td>

                    {{--<td class="tth">{{ ts('PHONENUMBER') }}</td>
                    <td>{{ $data->cell_phone }}</td>
                    <td class="tth">{{ ts('WECHATID') }}</td>
                    <td>{{ $data->wechat_id }}</td>--}}
                </tr>
                <tr>
                    <td class="tth">{{ ts('region') }}</td>
                    <td>{{ ts('region_master.'.$data->region_id) }}</td>
                    <td class="tth">{{ ts('province') }}</td>
                    <td>{{ ts('province_master.'.$data->province_id) }}</td>
                    <td class="tth">{{ ts('city') }}</td>
                    <td>{{ ts('cities.'.$data->city) }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('addresss') }}</td>
                    <td colspan="5">{{ $data->address }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('报价系统使用情况') }}</td>
                </tr>
                @if (!empty($dealer) && !empty($dealer->system_info))
                    <tr>
                        <td colspan="2">{{ ts('使用人') }}</td>
                        <td colspan="2">{{ ts('系统类别') }}</td>
                        <td colspan="2">{{ ts('PHONENUMBER') }}</td>
                    </tr>
                    @foreach($dealer->system_info as $item)
                    <tr>
                        <td colspan="2">{{ $item['system_user'] ?? '' }}</td>
                        <td colspan="2">{{ $item['system_name'] ?? '' }}</td>
                        <td colspan="2">{{ $item['system_phone'] ?? '' }}</td>
                    </tr>
                    @endforeach
                @endif
                <tr>
                    <td colspan="6" class="tst">{{ ts('店面图片') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt p-3">
                        <div class="warranty-image-wrapper" id="warrantyImageWrapper">
                            <div class="warranty-image-list">
                                @if (!empty($dealer) && !empty($dealer->store_pictures))
                                @foreach($dealer->store_pictures as $v)
                                    <div class="item">
                                        <img src="{{ getInstallPicture($v) }}">
                                    </div>
                                @endforeach
                                @endif
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('合同扫描图片') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt p-3">
                        <div class="warranty-image-wrapper" id="warrantyImageWrapper">
                            <div class="warranty-image-list">
                                @if (!empty($dealer) && !empty($dealer->agreement_pictures))
                                    @foreach($dealer->agreement_pictures as $v)
                                        <div class="item">
                                            <img src="{{ getInstallPicture($v) }}">
                                        </div>
                                    @endforeach
                                @endif
                            </div>
                        </div>
                    </td>
                </tr>
                @if (!empty($dealer->cert_price))
                <tr>
                    <td colspan="6" class="tst">{{ ts('认证数据') }}</td>
                </tr>
                <tr>
                    @if (!empty($dealer->cert_picture))
                    <td class="tth">{{ ts('认证日期') }}</td>
                    <td class="ttd">{{ $dealer->cert_date  }}</td>
                    <td class="tth">{{ ts('认证费用') }}</td>
                    <td class="ttd">{{ $dealer->cert_price  }}</td>
                    <td class="tth">{{ ts('认证图片') }}</td>
                    <td class="ttd">
                        <img style="width:80px;height: 80px;" src="{{ getInstallPicture($dealer->cert_picture) }}">
                    </td>
                    @endif
                </tr>
                <!--<tr>
                    <td class="tth">认证技师</td>
                    <td class="ttd">
                        {{ $dealer->cert_person ?? '' }}
                    </td>
                    <td class="tth">认证状态</td>
                    <td class="ttd" colspan="3">{{ !empty($dealer->cert_status) ? ($dealer->cert_status == 1 ? '未完成' : '已完成') : '' }}</td>
                </tr>-->
                @endif
                <tr>
                    <td colspan="6" class="tst">{{ ts('BEIZHU') }}</td>
                </tr>
                <tr>
                    <td colspan="6" height="64">{{ $data->note }}</td>
                </tr>
                @if (!empty($data->check_reason))
                    <tr>
                        <td colspan="6" class="tst">{{ ts('审核原因') }}</td>
                    </tr>
                    <tr>
                        <td colspan="6" class="ttt" style="text-align: center; height: 40px;">{{ $data->check_reason }}</td>
                    </tr>
                @endif
                </tbody>
            </table>
            @empty($data->deleted_at)
                <div class="my-4">
                    @if (strcmp($data->status, '1') === 0)
                    <a href="/{{ request()->path() }}/edit" class="btn btn-primary">{{ ts('edit') }}</a>
                    @endif
                    @if (strcmp($data->check_status, '0') === 0 && $is_check == 1)
                        <button class="btn btn-primary" onclick="updateDealerStatus('{{ $data->id }}', '1')">{{ ts('STA1') }}</button>
                        <button class="btn btn-primary" onclick="updateDealerStatus('{{ $data->id }}', '2')">{{ ts('REJECTION') }}</button>
                    @endif
                </div>
            @endif
            <h3 class="section_sub_title">{{ ts('LSBGJL') }}</h3>
            <table class="table s3 text-center">
                <thead>
                <tr class="table-secondary">
                    <th>{{ ts('CZY') }}</th>
                    <th>{{ ts('CZe') }}</th>
                    <th>{{ ts('explain') }}</th>
                    <th>{{ ts('CZsj') }}</th>
                </tr>
                @foreach(getUSH($data->id) as $v)
                    <tr>
                        <td>{{ $v->abbr }}</td>
                        <td class="bg-light">{{ ts('urstatus'.$v->status) }}</td>
                        <td class="bg-light">
{{--                            @if($v->status == 9)--}}

{{--                                @foreach(json_decode($v->note, 1) ?: [] as $vn)--}}
{{--                                    <div><b>{{ @$vn['label'] }}</b>：{{ json_encode(@$vn['old'] ) }} => {{ json_encode(@$vn['new'])  }}</div>--}}
{{--                              --}}
{{--                                @endforeach--}}

{{--                            @else--}}
{{--                                {{ $v->note }}--}}
{{--                            @endif--}}
                            @if($v->status == 9)
                                @foreach(json_decode($v->note, 1) ?: [] as $vn)
                                    <div>
                                        <b>{{ $vn['label']}}</b>：
                                        {{getLabelInfo($vn['label'],$vn['old'])}}
                                        =>
                                        {{getLabelInfo($vn['label'],$vn['new'])}}
                                    </div>
                                @endforeach
                            @else
                                {{ $v->note }}
                            @endif
                        </td>
                        <td>{{ fdate2($v->created_at) }}</td>
                    </tr>
                @endforeach
                </thead>
            </table>
        </div>


    </div>


@endsection
<script>
    function updateDealerStatus(id, status) {
        var url = '/admin/dealer/update_status/' + id;
        if (status == 1) {
            title = "确定通过";
        } else {
            title = '确定拒绝';
        }
        sweetAlert({
            title: title,
            text: status == 1 ? '请注意核查陕西、山东、青海、宁夏、内蒙、云南省代和直营区域的店面是否已收质保金!!!' : '',
            content: "input",
            // icon: "warning",
            buttons: {
                cancel: {
                    text: "<?php echo e(ts('CANCEL')); ?>",
                    value: false,
                    visible: true,
                    className: "",
                    closeModal: true,
                },
                confirm: {
                    text: "<?php echo e(ts('CONFIRM')); ?>",
                    value: true,
                    visible: true,
                    className: "",
                    closeModal: false
                }
            },
        }).then(function (d) {
            if (d === false) {
                return;
            }
            request.get(url, {
                params: {
                    id: id,
                    reason: d,
                    status: status,
                }
            }).then( function(d) {
                sweetAlert({
                    title: "<?php echo e(ts('DELETESUCCESS')); ?>",
                    icon: "success",
                    button:'<?php echo e(ts('CONFIRM')); ?>'
                }).then( function(d) {
                    window.location.reload()
                })
            }).catch( function(d) {
                if (d == 1) {
                    sweetAlert({
                        title: "操作成功",
                        icon: "success",
                        button:'<?php echo e(ts('CONFIRM')); ?>'
                    }).then( function(d) {
                        window.location.reload()
                    });
                } else {
                    sweetAlert({
                        title: d.msg,
                        icon: "error",
                        button:'<?php echo e(ts('CONFIRM')); ?>'
                    })
                }
            })
        }).catch(function (d) {
            if (d === false) {
                return;
            }
            sweetAlert({
                title: "审核成功",
                icon: "success",
                button:'<?php echo e(ts('CONFIRM')); ?>'
            }).then( function(d) {
                window.location.reload()
            })
        })
    }
</script>
